package com.yami.shop.common.config;


import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.data.redis.core.script.RedisScript;

/**
 * @author DELL
 */
@Configuration
@Slf4j
public class RedisConfig {

    @Bean
    public RedisScript<Long> likeScript() {
        Resource scriptSource = new ClassPathResource("scripts/like.lua");
        log.info("Loading like script: {}", scriptSource.exists()); // 检查文件是否存在

        return RedisScript.of(scriptSource, Long.class);
    }

    @Bean
    public RedisScript<Long> unlikeScript() {
        Resource scriptSource = new ClassPathResource("scripts/unlike.lua");
        log.info("Loading like script: {}", scriptSource.exists()); // 检查文件是否存在

        return RedisScript.of(scriptSource, Long.class);
    }
}